﻿@using Webdiyer.WebControls.Mvc
@using HiLand.General.Entity
@using HiLand.Utility4.MVC
@using GBFinance.Entity
@using GBFinance.Web.Models
@using HiLand.General
@using HiLand.Utility4.MVC.Data
@model PagedList<LoanBasicExtEntity>
@{
    ViewBag.Title = "Loan List";
    string queryName = this.GetPassedParam("queryName");
    string queryValue = this.GetPassedParam("queryValue");

    string queryDateBegin = this.GetPassedParam("queryDateBegin");
    string queryDateEnd = this.GetPassedParam("queryDateEnd");

    LoanTypes loanType = Miscs.GetCurrentLoanType();
    string loanListUrl = string.Empty;
    string sectionName = string.Empty;
    string sectionItemName = string.Empty;
    string pageTitle = string.Empty;
    decimal allAmount= 0.0M;
    int loanCount = 0;
    
    if(loanType== LoanTypes.Secured)
    {
        loanListUrl = Url.Action("SecuredLoanList");
        sectionName = "aSecuredLoanSection";
        sectionItemName = "aSecuredLoanList";
        pageTitle = "Secured Loan List";
    }
    else
    {
        loanListUrl = Url.Action("UnSecuredLoanList");
        sectionName = "aUnSecuredLoanSection";
        sectionItemName = "aUnSecuredLoanList";
        pageTitle = "UnSecured Loan List";
    }
}
<style type="text/css">
    .modalFix
    {
        width: 650px;
    }
    
    form td
    {
        vertical-align:middle;
    }
</style>
<h2>
    @pageTitle</h2>
<div id="ItemListDIV">
    @using (Html.BeginForm())
    {
        <table>
            <tr>
                <td>
                <select name="queryConditionName" id="queryConditionName">
            <option value="">Please select...</option>
            @if (queryName == "CustomerNo")
            {
                <option value="CustomerNo" selected="selected">Customer No.</option>
            }
            else
            { 
                <option value="CustomerNo">Customer No.</option>
            }

            @if (queryName == "BusinessName")
            {
                <option value="BusinessName" selected="selected">Business Name</option>
            }
            else
            { 
                <option value="BusinessName">Business Name</option>
            }

            @if (queryName == "MainApplicant")
            {
                <option value="MainApplicant" selected="selected">Main Applicant</option>
            }
            else
            { 
                <option value="MainApplicant">Main Applicant</option>
            }

            @if (queryName == "Email")
            {
                <option value="Email" selected="selected">Email</option>
            }
            else
            { 
                <option value="Email">Email</option>
            }

            @if (queryName == "Approved")
            {
                <option value="Approved" selected="selected">Approved</option>
            }
            else
            { 
                <option value="Approved">Approved</option>
            }
            @if (queryName == "Rejected")
            {
                <option value="Rejected" selected="selected">Rejected</option>
            }
            else
            { 
                <option value="Rejected">Rejected</option>
            }
            @if (queryName == "Deleted")
            {
                <option value="Deleted" selected="selected">Deleted</option>
            }
            else
            { 
                <option value="Deleted">Deleted</option>
            }
            @if (queryName == "Blacklisted")
            {
                <option value="Blacklisted" selected="selected">Blacklisted</option>
            }
            else
            { 
                <option value="Blacklisted">Blacklisted</option>
            }

            @if (queryName == "Collection")
            {
                <option value="Collection" selected="selected">Collection</option>
            }
            else
            { 
                <option value="Collection">Collection</option>
            }
        </select></td>
                <td><input name="queryConditionValue" id="queryConditionValue" value="@queryValue" /></td>
                <td>Date:</td>
                <td><input id="queryDateBegin" name="queryDateBegin" class="datePicker" value="@queryDateBegin" /></td>
                <td>-</td>
                <td><input id="queryDateEnd" name="queryDateEnd" class="datePicker" value="@queryDateEnd" /></td>
                <td><input type="button" id="btnQuery" value="Query" /></td>
                <td style="width:20%"></td>
            </tr>
        </table>
    }
    <table width="98%" class="grid">
        <tr>
            <th style="width: 30px">
                Costom No.
            </th>
            <th style="width: 80px">
                 Enterprise Name
            </th>
            <th style="width: 80px">
                Loan Amount
            </th>
            <th style="width: 60px">
                Loan Date
            </th>
            <th style="width: 60px">
                Main Applicant
            </th>
            <th style="width: 60px">
                Email
            </th>
            <th>
               Loan Status
            </th>
        </tr>
        @foreach (LoanBasicExtEntity entity in Model)
        {
            allAmount+= entity.LoanAmount;
            loanCount++;
            
            <tr>
                <td>@entity.EnterpriseIndexID
                </td>
                <td>@entity.LoanUserRealName
                </td>
                <td>@entity.LoanAmount.ToString()
                </td>
                <td>@entity.LoanDate.ToString(Miscs.DateTimeFormating)
                </td>
                <td>@entity.MainApplicant
                </td>
                <td>@entity.Email
                </td>
                <td>
                        @entity.LoanStatus.ToString()
                </td>
            </tr>   
        }
    </table>
    @{
        decimal commissionFee = 0.0M;
        if(loanType== LoanTypes.Secured)
        {
            commissionFee = allAmount * 0.01M;
            if (commissionFee < 50)
            {
                commissionFee = 50;
            }

            if (commissionFee > 200)
            {
                commissionFee = 200;
            }
        }
        else
        {
            commissionFee = 50 * loanCount;
        }
        }
    <div style="text-align:right">Commission Fee:$ @commissionFee.ToString("0.00")</div>
        <div class="modal modalFix" id="EnterpriseNoteDisplayDIV">
    </div>
    <div class="modal modalFix" id="EnterpriseFollowUpHistoryDisplayDIV">
    </div>
    <div class="modal modalFix" id="LoanStatusDisplayDIV">
    </div>
    @Html.Pager(Model, new PagerOptions() { PageIndexParameterName = "id", ShowDisabledPagerItems = false, AlwaysShowFirstLastPageNumber = true })
    
    <script type="text/javascript">
        $(document).ready(function () {
            $("#@sectionName").addClass("current");
            $("#@sectionItemName").addClass("current");

            $(".datePicker").datePicker({ startDate: '01/01/2010' });

            $(".modalInput").overlay({
                mask: {
                    color: '#ebecff',
                    loadSpeed: 200,
                    opacity: 0.9
                },
                closeOnClick: false
            });

            $("#btnQuery").click(function () {
                var queryName = $("#queryConditionName").val();
                var queryValue = $("#queryConditionValue").val();
                var queryDateBegin= $("#queryDateBegin").val();
                var queryDateEnd= $("#queryDateEnd").val();
                var url = $.UrlUtil("@loanListUrl").concat("queryConditionName",queryName).concat("queryConditionValue",queryValue).concat("queryDateBegin",queryDateBegin).concat("queryDateEnd",queryDateEnd).show(); 
                window.location = url;
            });
        });
    </script>
</div>
